package com.htfyun.fragment.settings;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.htfyun.fragment.library.LibraryMainFragment;
import com.htfyun.fragment.library.LibraryMainPagerFragmentAdapter;
import com.htfyun.view.NoScrollViewPager;

import org.geometerplus.zlibrary.ui.android.BuildConfig;
import org.geometerplus.zlibrary.ui.android.R;

import me.yokeyword.fragmentation.SupportFragment;

/**
 * Created by sst on 2018/1/26.
 */

public class SettingsMainFragment extends SupportFragment {

    private TabLayout mTab;
    private NoScrollViewPager mViewPager;

    public static SettingsMainFragment newInstance() {

        Bundle args = new Bundle();

        SettingsMainFragment fragment = new SettingsMainFragment();
        fragment.setArguments(args);
        return fragment;
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.htfyun_settings_main_fragment, container, false);
        initView(view);
        return view;
    }

    private void initView(View view) {
        mTab = (TabLayout) view.findViewById(R.id.tab);
        mViewPager = (NoScrollViewPager) view.findViewById(R.id.viewPager);
        mViewPager.setNoScroll(true);

        mTab.addTab(mTab.newTab());
        mTab.addTab(mTab.newTab());
        if (!BuildConfig.USE_PHONE) {
            mTab.setEinkUpdateMode( (short)4, (short)4);
        }
    }

    @Override
    public void onLazyInitView(@Nullable Bundle savedInstanceState) {
        super.onLazyInitView(savedInstanceState);
        String wifi = getString(R.string.wifi);
        String about = getString(R.string.about);
        mViewPager.setAdapter(new SettingsMainPagerFragmentAdapter(getChildFragmentManager()
                , wifi, about));
        mTab.setupWithViewPager(mViewPager);
    }
    
}
